package ControllerLayer;

import ModelLayer.Employee;
import ModelLayer.EmployeeCon;


/**
 * EmployeeCtr functions as a controller for the Employee and EmployeeCon classes in the ModelLayer.
 * Any changes to those classes will go through EmployeeCtr.
 * 
 * @author anna
 *
 */
public class EmployeeCtr {
    private EmployeeCon employeeCon;
    //private RandomPassword randomPassword = RandomPassword.getInstance();

    /**
     * Constructor for EmployeeCtr.
     */
    public EmployeeCtr() {
        employeeCon = EmployeeCon.getInstance();
    }

    /**
     * Method for creating an employee object taking input parameters from the UI.
     * 
     * @param name          the employees name.
     * @param address       the employees address.
     * @param email         the employees email.
     * @param tlf           the employees phonenumber.
     * 
     * @throws Exception    if the employee object is already contained in the container.
     */
    public void createEmployee(String name, String address, String email, String tlf) throws Exception{
        //String password = randomPassword.generatePassword();
        String password = "";
        Employee e = new Employee(name, address, email, tlf, password);
        employeeCon.addEmployee(e);
    }

    /**
     * Method for returning an Employee object taking the id-number of the employee as parameter.
     * 
     * @param employeeNo    The id-number of an employee.
     * 
     * @return              An Employee object.
     */
    public Employee getEmployee(int employeeNo){
        return employeeCon.getEmployee(employeeNo);
    }

    /**
     * A method to set new values for the fields of Employee objects.
     * Takes the input parameters from UI.
     * 
     * @param employeeNo    The id-number of an employee.
     * @param newName       The new name of an employee.
     * @param newAddress    The new address of an employee
     * @param newEmail      The new e-mail address of an employee.
     * @param newTlf        The new  phone number of an employee.
     * @param newPassword   The new password of an employee. 
     */
    public void updateEmployee(int employeeNo, String newName, String newAddress, String newEmail, String newTlf/*, String newPassword*/){
        Employee e = employeeCon.getEmployee(employeeNo);
        e.setName(newName);
        e.setAddress(newAddress);
        e.setEmail(newEmail);
        e.setTlf(newTlf);
        //e.setPassword(newPassword);
    }

    /**
     * Method for removing an employee.
     * 
     * @param employeeNo    The id-number of the employee.
     */
    public void deleteEmployee(int employeeNo){
        employeeCon.deleteEmployee(employeeNo);
    }
    
    /**
     * 
     * @param e             A object of the type employee. 
     */
    public void setCurrentEmployee(Employee e){
        employeeCon.setCurrentEmployee(e);
    }
    
    /**
     * 
     * @return              A object of the type employee.
     */
    public Employee getCurrentEmployee(){
        return employeeCon.getCurrentEmployee();
    }

}
